Skip to content

Conversation

@yiqiangin
Copy link
Contributor

In order to migrate all the transformers in which any of operatorTransformer, operandTransformer and resultTransformer is defined as a JSON string into the transformers which define the transformation rule in native Java code, the following code changes are made in this PR:

Adding some classes to implement the transformers which extends SourceOperatorMatchSqlCallTransformer and the specific transformation logic is defined as native Java code including

  • DateDiffOperatorTransformer
  • DateSubOperatorTransformer
  • DateAddOperatorTransformer
  • DecodeOperatorTransformer
  • RegexpExtractOperatorTransformer
  • ModOperatorTransformer
  • TruncateOperatorTransformer
  • RandomIntegerOperatorWithTwoOperandsTransformer
  • RandomOperatorWithOneOperandTransformer

Removing the code of JsonSqlCallTransformer

To be noted that this is the replacement of PR #350

Copy link
Collaborator

@ljfgem ljfgem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @yiqiangin for this PR!
Please add the test part in the PR description.

* matches the target values in the condition function.
*/
public abstract class SourceOperatorMatchSqlCallTransformer extends SqlCallTransformer {
public static final SqlOperator TIMESTAMP_OPERATOR =
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be protected.

}
};

protected final SqlOperator DATE_OPERATOR = new SqlUserDefinedFunction(new SqlIdentifier("date", SqlParserPos.ZERO),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be static, should be aligned with TIMESTAMP_OPERATOR above.

// math functions
new OperatorRenameSqlCallTransformer(SqlStdOperatorTable.RAND, 0, "RANDOM"),
new JsonTransformSqlCallTransformer(SqlStdOperatorTable.RAND, 1, "RANDOM", "[]", null, null),
new RandomOperatorWithOneOperandTransformer(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we just use OperatorRenameSqlCallTransformer for this case?

Comment on lines +38 to +40
List<SqlNode> newOperands = new ArrayList<>();
newOperands.add(sqlCall.getOperandList().get(1));
return createCall(TARGET_OPERATOR, newOperands, SqlParserPos.ZERO);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be simplified to return TARGET_OPERATOR.createCall(sqlCall.getParserPosition(), sqlCall.getOperandList().get(1));, and many similar parts can be simplified in this PR.


/**
* This class is a subclass of {@link SourceOperatorMatchSqlCallTransformer} which transforms a Coral SqlCall of "date_add"
* operator with 2 operands into a Trino SqlCall of an operator named "date_add"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add examples for each transformer in the class javadoc.

Comment on lines +36 to +38
private static final SqlOperator HIVE_PATTERN_TO_TRINO_OPERATOR =
new SqlUserDefinedFunction(new SqlIdentifier("hive_pattern_to_trino", SqlParserPos.ZERO),
FunctionReturnTypes.STRING, null, OperandTypes.STRING, null, null);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we just use createSqlOperator? Feel that the operand type is not necessary here.

@ljfgem ljfgem changed the title Migrate UDF operator transformers based on JSON-infra into transformers based on native Java code Coral-Trino: Migrate UDF operator transformers based on JSON-infra into transformers based on native Java code Feb 15, 2023
@yiqiangin yiqiangin closed this by deleting the head repository Sep 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants